import { message } from 'antd';
import { history } from 'umi';
import { addSite,fetchSite,updateSite } from './service';

const Model = {
  namespace: 'cubeSite',
  state: {
    currentSite:{}
  },
  effects: {
    *add({ payload }, { call }) {
      let result=yield call(addSite, payload);
      if(result.code===0){
        message.success('提交成功');
        history.push(`/site/center/${payload.venueId}`)
      }else{
        message.error(result.message);
      }
    },
    *update({ payload }, { call }) {
      let result=yield call(updateSite, payload);
      if(result.code===0){
        message.success('提交成功');
        history.push(`/site/center/${payload.venueId}`)
      }else{
        message.error(result.message);
      }
    },
    *fetchSite({ payload }, { call,put }) {
      let result=yield call(fetchSite, payload);
      if(result.code===0){
        yield put({
          type: 'common',
          payload: {
            currentSite:result.data
          }
        });
      }else{
        message.error(result.message);
      }
    },
  },
  reducers: {
    common(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
  },
};
export default Model;
